//
//  BaseViewController.m
//  SegmentDemo
//
//  Created by 塔兮 on 2022/4/11.
//

#import "BaseViewController.h"

@interface BaseViewController ()

@property (nonatomic, strong) UIButton *button;
@property (nonatomic, strong) UIView *viewOne;
@property (nonatomic, strong) UIView *viewTwo;
@property (nonatomic, assign) NSInteger num;

@end

@implementation BaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self configureView];
}

- (UIView *)viewOne {
    if (!_viewOne) {
        _viewOne = [UIView new];
        _viewOne.backgroundColor = UIColor.redColor;
    }
    return _viewOne;
}

- (UIView *)viewTwo {
    if (!_viewTwo) {
        _viewTwo = [UIView new];
        _viewTwo.backgroundColor = UIColor.blueColor;
    }
    return _viewTwo;
}

- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeSystem];
        _button.backgroundColor = UIColorFromHex(@"FFFFFF");
        _button.titleLabel.font = FONT_SIZE(14);
        [_button setTitle:self.title forState:UIControlStateNormal];
        [_button setTitleColor:UIColorFromHex(@"000000") forState:UIControlStateNormal];
        [_button setBorderWidth:1 color:UIColorFromHex(@"F5F5F5") radius:5];
        [_button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    }
    return _button;
}

- (void)configureView {
    self.view.backgroundColor = self.backColor;
    [self.view addSubview:self.viewOne];
    [self.view addSubview:self.viewTwo];
    [self.view addSubview:self.button];
    
    [self.viewOne mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).mas_offset(100);
        make.left.mas_equalTo(self.view).mas_offset(50);
        make.width.height.mas_offset(100);
    }];
    
    [self.viewTwo mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view).mas_offset(120);
        make.left.mas_equalTo(self.view).mas_offset(100);
        make.width.height.mas_offset(100);
    }];
    
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.centerY.mas_equalTo(self.view.mas_centerY);
        make.height.mas_offset(30);
        make.width.mas_offset(100);
    }];
}

- (void)buttonAction {
//    [self.view addSubview:self.viewOne];
//    [self.view addSubview:self.viewTwo];
    if (self.num == 0) {
        self.num = 1;
        [self.view sendSubviewToBack:self.viewOne];
        [self.view bringSubviewToFront:self.viewTwo];
        
        return;
    }
    
    if (self.num == 1) {
        self.num = 0;
        
        [self.view sendSubviewToBack:self.viewTwo];
        [self.view bringSubviewToFront:self.viewOne];
        
        return;
    }
    
//    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"点击了按钮" message:self.title preferredStyle:(UIAlertControllerStyleAlert)];
//
//    [alert addAction:[UIAlertAction actionWithTitle:@"确定" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
//
//    }]];
//
//    [self presentViewController:alert animated:NO completion:nil];
}

@end
